#pragma once

#include <QObject>
#include <QMap>
#include <QScopedPointer>

#include "Action.h"
#include "PublicKey.h"

namespace kryptos { namespace controller {

class EncryptionOperationsManager : public QObject
{
  Q_OBJECT
  public:

    static EncryptionOperationsManager& manager();

    void encrypt(QMap<QString, QString> params);
    void decrypt(QMap<QString, QString> params);

public slots:
    void slotResumeDecryption(const std::string& passphrase);

signals:
    void passphraseNeeded           (const kryptos::entities::KeyInfo&);
    void wrongPassphrase            (const kryptos::entities::KeyInfo&);
    void usersSelectionIsEmpty      ();
    void encryptionOperationStarted ();
    void encryptionOperationEnded   ();
    void encryptionOperationProgress(int);
    void encryptionOperationError   (QString);

private slots:
    void slotEncryptFinished(bool success);
    void slotDecryptFinished(bool success);

private:
    EncryptionOperationsManager();

    void connectActionSignals();

    kryptos::entities::KeyInfo lookForIdentityInRecipients(std::string encryptedFile);

    int                        m_lastSourceType;
    std::vector<unsigned char> m_lastSelection;
    kryptos::entities::KeyInfo m_lastIdentityInfo;
    std::string                m_lastPassphrase;

    QScopedPointer<kryptos::actions::Action> m_currentAction;
};

}}
